home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_network_io.h.z / apr_network_io.h
C/C++ Source or Header  |  2002-07-08  |  32KB  |  834 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_NETWORK_IO_H
  56. #define APR_NETWORK_IO_H
  57. /**
  58.  * @file apr_network_io.h
  59.  * @brief APR Network library
  60.  */
  61. /**
  62.  * @defgroup APR_Net Network Routines
  63.  * @ingroup APR
  64.  * @{
  65.  */
  66.  
  67. #include "apr.h"
  68. #include "apr_pools.h"
  69. #include "apr_file_io.h"
  70. #include "apr_errno.h"
  71. #include "apr_inherit.h" 
  72.  
  73. #if APR_HAVE_NETINET_IN_H
  74. #include <netinet/in.h>
  75. #endif
  76.  
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif /* __cplusplus */
  80.  
  81. #ifndef MAX_SECS_TO_LINGER
  82. #define MAX_SECS_TO_LINGER 30
  83. #endif
  84.  
  85. #ifndef APRMAXHOSTLEN
  86. #define APRMAXHOSTLEN 256
  87. #endif
  88.  
  89. #ifndef APR_ANYADDR
  90. #define APR_ANYADDR "0.0.0.0"
  91. #endif
  92.  
  93. /**
  94.  * @defgroup Sock_opt Socket option definitions
  95.  * @{
  96.  */
  97. #define APR_SO_LINGER        1
  98. #define APR_SO_KEEPALIVE     2
  99. #define APR_SO_DEBUG         4
  100. #define APR_SO_NONBLOCK      8
  101. #define APR_SO_REUSEADDR     16
  102. #define APR_SO_TIMEOUT       32
  103. #define APR_SO_SNDBUF        64
  104. #define APR_SO_RCVBUF        128
  105. #define APR_SO_DISCONNECTED  256
  106. #define APR_TCP_NODELAY      512
  107. #define APR_TCP_NOPUSH       1024
  108. #define APR_RESET_NODELAY    2048 /**< This flag is ONLY set internally
  109.                                    * when we set APR_TCP_NOPUSH with
  110.                                    * APR_TCP_NODELAY set to tell us that
  111.                                    * APR_TCP_NODELAY should be turned on
  112.                                    * again when NOPUSH is turned off
  113.                                    */
  114. #define APR_INCOMPLETE_READ 4096  /**< Set on non-blocking sockets
  115.                    * (APR_SO_TIMEOUT != 0) on which the
  116.                    * previous read() did not fill a buffer
  117.                    * completely.  the next apr_recv() will
  118.                    * first call select()/poll() rather than
  119.                    * going straight into read().  (Can also
  120.                    * be set by an application to force a
  121.                    * select()/poll() call before the next
  122.                    * read, in cases where the app expects
  123.                    * that an immediate read would fail.)
  124.                    */
  125. #define APR_INCOMPLETE_WRITE 8192 /* like APR_INCOMPLETE_READ, but for write
  126.                                    */
  127.  
  128. #define APR_POLLIN    0x001 
  129. #define APR_POLLPRI   0x002
  130. #define APR_POLLOUT   0x004
  131. #define APR_POLLERR   0x010
  132. #define APR_POLLHUP   0x020
  133. #define APR_POLLNVAL  0x040
  134. /** @} */
  135.  
  136. typedef enum {APR_SHUTDOWN_READ, APR_SHUTDOWN_WRITE, 
  137.           APR_SHUTDOWN_READWRITE} apr_shutdown_how_e;
  138.  
  139. #if (!APR_HAVE_IN_ADDR)
  140. /**
  141.  * We need to make sure we always have an in_addr type, so APR will just
  142.  * define it ourselves, if the platform doesn't provide it.
  143.  */
  144. struct in_addr {
  145.     apr_uint32_t  s_addr; /**< storage to hold the IP# */
  146. };
  147. #endif
  148.  
  149. /**
  150.  * @def APR_INET
  151.  * Not all platforms have these defined, so we'll define them here
  152.  * The default values come from FreeBSD 4.1.1
  153.  */
  154. #define APR_INET     AF_INET
  155. /** @def APR_UNSPEC
  156.  * Let the system decide which address family to use
  157.  */
  158. #ifdef AF_UNSPEC
  159. #define APR_UNSPEC   AF_UNSPEC
  160. #else
  161. #define APR_UNSPEC   0
  162. #endif
  163. #if APR_HAVE_IPV6
  164. #define APR_INET6    AF_INET6
  165. #endif
  166.  
  167. /**
  168.  * Enum to tell us if we're interested in remote or local socket
  169.  */
  170. typedef enum {
  171.     APR_LOCAL,
  172.     APR_REMOTE
  173. } apr_interface_e;
  174.  
  175. /* I guess not everybody uses inet_addr.  This defines apr_inet_addr
  176.  * appropriately.
  177.  */
  178.  
  179. #if APR_HAVE_INET_ADDR
  180. #define apr_inet_addr    inet_addr
  181. #elif APR_HAVE_INET_NETWORK        /* only DGUX, as far as I know */
  182. /**
  183.  * @warning
  184.  * not generally safe... inet_network() and inet_addr() perform
  185.  * different functions */
  186. #define apr_inet_addr    inet_network
  187. #endif
  188.  
  189. typedef struct apr_socket_t     apr_socket_t;
  190. typedef struct apr_pollfd_t     apr_pollfd_t;
  191. /**
  192.  * A structure to encapsulate headers and trailers for apr_sendfile
  193.  */
  194. typedef struct apr_hdtr_t       apr_hdtr_t;
  195. typedef struct in_addr          apr_in_addr_t;
  196. /** A structure to represent an IP subnet */
  197. typedef struct apr_ipsubnet_t apr_ipsubnet_t;
  198.  
  199. /** @remark use apr_uint16_t just in case some system has a short that isn't 16 bits... */
  200. typedef apr_uint16_t            apr_port_t;
  201.  
  202. /* It's defined here as I think it should all be platform safe...
  203.  */
  204. /**
  205.  * APRs socket address type, used to ensure protocol independence
  206.  */
  207. typedef struct apr_sockaddr_t apr_sockaddr_t;
  208.  
  209. struct apr_sockaddr_t {
  210.     /** The pool to use... */
  211.     apr_pool_t *pool;
  212.     /** The hostname */
  213.     char *hostname;
  214.     /** Either a string of the port number or the service name for the port */
  215.     char *servname;
  216.     /** The numeric port */
  217.     apr_port_t port;
  218.     /** The family */
  219.     apr_int32_t family;
  220.     union {
  221.         /** IPv4 sockaddr structure */
  222.         struct sockaddr_in sin;
  223. #if APR_HAVE_IPV6
  224.         /** IPv6 sockaddr structure */
  225.         struct sockaddr_in6 sin6;
  226. #endif
  227.     } sa;
  228.     /** How big is the sockaddr we're using? */
  229.     apr_socklen_t salen;
  230.     /** How big is the ip address structure we're using? */
  231.     int ipaddr_len;
  232.     /** How big should the address buffer be?  16 for v4 or 46 for v6
  233.      *  used in inet_ntop... */
  234.     int addr_str_len;
  235.     /** This points to the IP address structure within the appropriate
  236.      *  sockaddr structure.  */
  237.     void *ipaddr_ptr;
  238.     /** If multiple addresses were found by apr_sockaddr_info_get(), this 
  239.      *  points to a representation of the next address. */
  240.     apr_sockaddr_t *next;
  241. };
  242.  
  243. #if APR_HAS_SENDFILE
  244. /* Define flags passed in on apr_sendfile() */
  245. #define APR_SENDFILE_DISCONNECT_SOCKET      1
  246. #endif
  247.  
  248. /** A structure to encapsulate headers and trailers for apr_sendfile */
  249. struct apr_hdtr_t {
  250.     /** An iovec to store the headers sent before the file. 
  251.      *  @defvar iovec *headers */
  252.     struct iovec* headers;
  253.     /** number of headers in the iovec */
  254.     int numheaders;
  255.     /** An iovec to store the trailers sent after the file. 
  256.      *  @defvar iovec *trailers */
  257.     struct iovec* trailers;
  258.     /** number of trailers in the iovec */
  259.     int numtrailers;
  260. };
  261.  
  262. /* function definitions */
  263.  
  264. /**
  265.  * Create a socket.
  266.  * @param new_sock The new socket that has been set up.
  267.  * @param family The address family of the socket (e.g., APR_INET).
  268.  * @param type The type of the socket (e.g., SOCK_STREAM).
  269.  * @param cont The pool to use
  270.  */
  271. APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock, 
  272.                                             int family, int type,
  273.                                             apr_pool_t *cont);
  274.  
  275. /**
  276.  * Shutdown either reading, writing, or both sides of a socket.
  277.  * @param thesocket The socket to close 
  278.  * @param how How to shutdown the socket.  One of:
  279.  * <PRE>
  280.  *            APR_SHUTDOWN_READ         no longer allow read requests
  281.  *            APR_SHUTDOWN_WRITE        no longer allow write requests
  282.  *            APR_SHUTDOWN_READWRITE    no longer allow read or write requests 
  283.  * </PRE>
  284.  * @remark This does not actually close the socket descriptor, it just
  285.  *      controls which calls are still valid on the socket.
  286.  */
  287. APR_DECLARE(apr_status_t) apr_shutdown(apr_socket_t *thesocket,
  288.                                        apr_shutdown_how_e how);
  289.  
  290. /**
  291.  * Close a socket.
  292.  * @param thesocket The socket to close 
  293.  */
  294. APR_DECLARE(apr_status_t) apr_socket_close(apr_socket_t *thesocket);
  295.  
  296. /**
  297.  * Bind the socket to its associated port
  298.  * @param sock The socket to bind 
  299.  * @param sa The socket address to bind to
  300.  * @remark This may be where we will find out if there is any other process
  301.  *      using the selected port.
  302.  */
  303. APR_DECLARE(apr_status_t) apr_bind(apr_socket_t *sock, apr_sockaddr_t *sa);
  304.  
  305. /**
  306.  * Listen to a bound socket for connections.
  307.  * @param sock The socket to listen on 
  308.  * @param backlog The number of outstanding connections allowed in the sockets
  309.  *                listen queue.  If this value is less than zero, the listen
  310.  *                queue size is set to zero.  
  311.  */
  312. APR_DECLARE(apr_status_t) apr_listen(apr_socket_t *sock, apr_int32_t backlog);
  313.  
  314. /**
  315.  * Accept a new connection request
  316.  * @param new_sock A copy of the socket that is connected to the socket that
  317.  *                 made the connection request.  This is the socket which should
  318.  *                 be used for all future communication.
  319.  * @param sock The socket we are listening on.
  320.  * @param connection_pool The pool for the new socket.
  321.  */
  322. APR_DECLARE(apr_status_t) apr_accept(apr_socket_t **new_sock, 
  323.                                      apr_socket_t *sock,
  324.                                      apr_pool_t *connection_pool);
  325.  
  326. /**
  327.  * Issue a connection request to a socket either on the same machine 
  328.  * or a different one.
  329.  * @param sock The socket we wish to use for our side of the connection 
  330.  * @param sa The address of the machine we wish to connect to.  If NULL,
  331.  *           APR assumes that the sockaddr_in in the apr_socket is 
  332.  *           completely filled out.
  333.  */
  334. APR_DECLARE(apr_status_t) apr_connect(apr_socket_t *sock, apr_sockaddr_t *sa);
  335.  
  336. /**
  337.  * Create apr_sockaddr_t from hostname, address family, and port.
  338.  * @param sa The new apr_sockaddr_t.
  339.  * @param hostname The hostname or numeric address string to resolve/parse.
  340.  * @param family The address family to use, or APR_UNSPEC if the system should 
  341.  *               decide.
  342.  * @param port The port number.
  343.  * @param flags Special processing flags.
  344.  * @param p The pool for the apr_sockaddr_t and associated storage.
  345.  */
  346. APR_DECLARE(apr_status_t) apr_sockaddr_info_get(apr_sockaddr_t **sa,
  347.                                           const char *hostname,
  348.                                           apr_int32_t family,
  349.                                           apr_port_t port,
  350.                                           apr_int32_t flags,
  351.                                           apr_pool_t *p);
  352.  
  353. /**
  354.  * Look up the host name from an apr_sockaddr_t.
  355.  * @param hostname The hostname.
  356.  * @param sa The apr_sockaddr_t.
  357.  * @param flags Special processing flags.
  358.  */
  359. APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
  360.                                           apr_sockaddr_t *sa,
  361.                                           apr_int32_t flags);
  362.                              
  363. /**
  364.  * Parse hostname/IP address with scope id and port.
  365.  *
  366.  * Any of the following strings are accepted:
  367.  *   8080                  (just the port number)
  368.  *   www.apache.org        (just the hostname)
  369.  *   www.apache.org:8080   (hostname and port number)
  370.  *   [fe80::1]:80          (IPv6 numeric address string only)
  371.  *   [fe80::1%eth0]        (IPv6 numeric address string and scope id)
  372.  *
  373.  * Invalid strings:
  374.  *                         (empty string)
  375.  *   [abc]                 (not valid IPv6 numeric address string)
  376.  *   abc:65536             (invalid port number)
  377.  *
  378.  * @param addr The new buffer containing just the hostname.  On output, *addr 
  379.  *             will be NULL if no hostname/IP address was specfied.
  380.  * @param scope_id The new buffer containing just the scope id.  On output, 
  381.  *                 *scope_id will be NULL if no scope id was specified.
  382.  * @param port The port number.  On output, *port will be 0 if no port was 
  383.  *             specified.
  384.  * @param str The input string to be parsed.
  385.  * @param p The pool from which *addr and *scope_id are allocated.
  386.  * @remark If scope id shouldn't be allowed, check for scope_id != NULL in 
  387.  *         addition to checking the return code.  If addr/hostname should be 
  388.  *         required, check for addr == NULL in addition to checking the 
  389.  *         return code.
  390.  */
  391. APR_DECLARE(apr_status_t) apr_parse_addr_port(char **addr,
  392.                                               char **scope_id,
  393.                                               apr_port_t *port,
  394.                                               const char *str,
  395.                                               apr_pool_t *p);
  396.  
  397. /**
  398.  * Get name of the current machine
  399.  * @param buf A buffer to store the hostname in.
  400.  * @param len The maximum length of the hostname that can be stored in the
  401.  *            buffer provided.  The suggested length is APRMAXHOSTLEN + 1.
  402.  * @param cont The pool to use.
  403.  * @remark If the buffer was not large enough, an error will be returned.
  404.  */
  405. APR_DECLARE(apr_status_t) apr_gethostname(char *buf, int len, apr_pool_t *cont);
  406.  
  407. /**
  408.  * Return the data associated with the current socket
  409.  * @param data The user data associated with the socket.
  410.  * @param key The key to associate with the user data.
  411.  * @param sock The currently open socket.
  412.  */
  413. APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
  414.                                              apr_socket_t *sock);
  415.  
  416. /**
  417.  * Set the data associated with the current socket.
  418.  * @param sock The currently open socket.
  419.  * @param data The user data to associate with the socket.
  420.  * @param key The key to associate with the data.
  421.  * @param cleanup The cleanup to call when the socket is destroyed.
  422.  */
  423. APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data,
  424.                                              const char *key,
  425.                                              apr_status_t (*cleanup)(void*));
  426.  
  427. /**
  428.  * Send data over a network.
  429.  * @param sock The socket to send the data over.
  430.  * @param buf The buffer which contains the data to be sent. 
  431.  * @param len On entry, the number of bytes to send; on exit, the number
  432.  *            of bytes sent.
  433.  * @remark
  434.  * <PRE>
  435.  * This functions acts like a blocking write by default.  To change 
  436.  * this behavior, use apr_setsocketopt with the APR_SO_TIMEOUT option.
  437.  *
  438.  * It is possible for both bytes to be sent and an error to be returned.
  439.  *
  440.  * APR_EINTR is never returned.
  441.  * </PRE>
  442.  */
  443. APR_DECLARE(apr_status_t) apr_send(apr_socket_t *sock, const char *buf, 
  444.                                    apr_size_t *len);
  445.  
  446. /**
  447.  * Send multiple packets of data over a network.
  448.  * @param sock The socket to send the data over.
  449.  * @param vec The array of iovec structs containing the data to send 
  450.  * @param nvec The number of iovec structs in the array
  451.  * @param len Receives the number of bytes actually written
  452.  * @remark
  453.  * <PRE>
  454.  * This functions acts like a blocking write by default.  To change 
  455.  * this behavior, use apr_setsocketopt with the APR_SO_TIMEOUT option.
  456.  * The number of bytes actually sent is stored in argument 3.
  457.  *
  458.  * It is possible for both bytes to be sent and an error to be returned.
  459.  *
  460.  * APR_EINTR is never returned.
  461.  * </PRE>
  462.  */
  463. APR_DECLARE(apr_status_t) apr_sendv(apr_socket_t *sock, 
  464.                                     const struct iovec *vec,
  465.                                     apr_int32_t nvec, apr_size_t *len);
  466.  
  467. /**
  468.  * @param sock The socket to send from
  469.  * @param where The apr_sockaddr_t describing where to send the data
  470.  * @param data The data to send
  471.  * @param len  The length of the data to send
  472.  */
  473. APR_DECLARE(apr_status_t) apr_sendto(apr_socket_t *sock, apr_sockaddr_t *where,
  474.                                      apr_int32_t flags, const char *buf, 
  475.                                      apr_size_t *len);
  476.  
  477. /**
  478.  * @param from The apr_sockaddr_t to fill in the recipient info
  479.  * @param sock The socket to use
  480.  * @param buf  The buffer to use
  481.  * @param len  The length of the available buffer
  482.  */
  483.  
  484. APR_DECLARE(apr_status_t) apr_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
  485.                                        apr_int32_t flags, char *buf, 
  486.                                        apr_size_t *len);
  487.  
  488. #if APR_HAS_SENDFILE || defined(DOXYGEN)
  489.  
  490. /**
  491.  * Send a file from an open file descriptor to a socket, along with 
  492.  * optional headers and trailers
  493.  * @param sock The socket to which we're writing
  494.  * @param file The open file from which to read
  495.  * @param hdtr A structure containing the headers and trailers to send
  496.  * @param offset Offset into the file where we should begin writing
  497.  * @param len (input)  - Number of bytes to send from the file 
  498.  *            (output) - Number of bytes actually sent, 
  499.  *                       including headers, file, and trailers
  500.  * @param flags APR flags that are mapped to OS specific flags
  501.  * @remark This functions acts like a blocking write by default.  To change 
  502.  *         this behavior, use apr_setsocketopt with the APR_SO_TIMEOUT option.
  503.  *         The number of bytes actually sent is stored in argument 5.
  504.  */
  505. APR_DECLARE(apr_status_t) apr_sendfile(apr_socket_t *sock, apr_file_t *file,
  506.                                        apr_hdtr_t *hdtr, apr_off_t *offset,
  507.                                        apr_size_t *len, apr_int32_t flags);
  508.  
  509. #endif /* APR_HAS_SENDFILE */
  510.  
  511. /**
  512.  * Read data from a network.
  513.  * @param sock The socket to read the data from.
  514.  * @param buf The buffer to store the data in. 
  515.  * @param len On entry, the number of bytes to receive; on exit, the number
  516.  *            of bytes received.
  517.  * @remark
  518.  * <PRE>
  519.  * This functions acts like a blocking read by default.  To change 
  520.  * this behavior, use apr_setsocketopt with the APR_SO_TIMEOUT option.
  521.  * The number of bytes actually sent is stored in argument 3.
  522.  *
  523.  * It is possible for both bytes to be received and an APR_EOF or
  524.  * other error to be returned.
  525.  *
  526.  * APR_EINTR is never returned.
  527.  * </PRE>
  528.  */
  529. APR_DECLARE(apr_status_t) apr_recv(apr_socket_t *sock, 
  530.                                    char *buf, apr_size_t *len);
  531.  
  532. /**
  533.  * Setup socket options for the specified socket
  534.  * @param sock The socket to set up.
  535.  * @param opt The option we would like to configure.  One of:
  536.  * <PRE>
  537.  *            APR_SO_DEBUG      --  turn on debugging information 
  538.  *            APR_SO_KEEPALIVE  --  keep connections active
  539.  *            APR_SO_LINGER     --  lingers on close if data is present
  540.  *            APR_SO_NONBLOCK   --  Turns blocking on/off for socket
  541.  *            APR_SO_REUSEADDR  --  The rules used in validating addresses
  542.  *                                  supplied to bind should allow reuse
  543.  *                                  of local addresses.
  544.  *            APR_SO_TIMEOUT    --  Set the timeout value in microseconds.
  545.  *                                  values < 0 mean wait forever.  0 means
  546.  *                                  don't wait at all.
  547.  *            APR_SO_SNDBUF     --  Set the SendBufferSize
  548.  *            APR_SO_RCVBUF     --  Set the ReceiveBufferSize
  549.  * </PRE>
  550.  * @param on Value for the option.
  551.  */
  552. APR_DECLARE(apr_status_t) apr_setsocketopt(apr_socket_t *sock,
  553.                                            apr_int32_t opt, apr_int32_t on);
  554.  
  555. /**
  556.  * Query socket options for the specified socket
  557.  * @param sock The socket to query
  558.  * @param opt The option we would like to query.  One of:
  559.  * <PRE>
  560.  *            APR_SO_DEBUG      --  turn on debugging information 
  561.  *            APR_SO_KEEPALIVE  --  keep connections active
  562.  *            APR_SO_LINGER     --  lingers on close if data is present
  563.  *            APR_SO_NONBLOCK   --  Turns blocking on/off for socket
  564.  *            APR_SO_REUSEADDR  --  The rules used in validating addresses
  565.  *                                  supplied to bind should allow reuse
  566.  *                                  of local addresses.
  567.  *            APR_SO_TIMEOUT    --  Set the timeout value in microseconds.
  568.  *                                  values < 0 mean wait forever.  0 means
  569.  *                                  don't wait at all.
  570.  *            APR_SO_SNDBUF     --  Set the SendBufferSize
  571.  *            APR_SO_RCVBUF     --  Set the ReceiveBufferSize
  572.  *            APR_SO_DISCONNECTED -- Query the disconnected state of the socket.
  573.  *                                  (Currently only used on Windows)
  574.  * </PRE>
  575.  * @param on Socket option returned on the call.
  576.  */
  577. APR_DECLARE(apr_status_t) apr_getsocketopt(apr_socket_t *sock, 
  578.                                            apr_int32_t opt, apr_int32_t *on);
  579.  
  580. /**
  581.  * Return an apr_sockaddr_t from an apr_socket_t
  582.  * @param sa The returned apr_sockaddr_t.
  583.  * @param which Which interface do we want the apr_sockaddr_t for?
  584.  * @param sock The socket to use
  585.  */
  586. APR_DECLARE(apr_status_t) apr_socket_addr_get(apr_sockaddr_t **sa,
  587.                                            apr_interface_e which,
  588.                                            apr_socket_t *sock);
  589.  
  590. /**
  591.  * Set the port in an APR socket address.
  592.  * @param sockaddr The socket address to set.
  593.  * @param port The port to be stored in the socket address.
  594.  */
  595. APR_DECLARE(apr_status_t) apr_sockaddr_port_set(apr_sockaddr_t *sockaddr,
  596.                                        apr_port_t port);
  597.  
  598. /**
  599.  * Return the port in an APR socket address.
  600.  * @param port The port from the socket address.
  601.  * @param sockaddr The socket address to reference.
  602.  */
  603. APR_DECLARE(apr_status_t) apr_sockaddr_port_get(apr_port_t *port,
  604.                                        apr_sockaddr_t *sockaddr);
  605.  
  606. /**
  607.  * Set the IP address in an APR socket address.
  608.  * @param sockaddr The socket address to use 
  609.  * @param addr The IP address to attach to the socket.
  610.  *             Use APR_ANYADDR to use any IP addr on the machine.
  611.  */
  612. APR_DECLARE(apr_status_t) apr_sockaddr_ip_set(apr_sockaddr_t *sockaddr,
  613.                                          const char *addr);
  614.  
  615. /**
  616.  * Return the IP address (in numeric address string format) in
  617.  * an APR socket address.
  618.  * @param addr The IP address.
  619.  * @param sockaddr The socket address to reference.
  620.  */
  621. APR_DECLARE(apr_status_t) apr_sockaddr_ip_get(char **addr, 
  622.                                          apr_sockaddr_t *sockaddr);
  623.  
  624. /**
  625.  * See if the IP addresses in two APR socket addresses are
  626.  * equivalent.  Appropriate logic is present for comparing
  627.  * IPv4-mapped IPv6 addresses with IPv4 addresses.
  628.  *
  629.  * @param addr1 One of the APR socket addresses.
  630.  * @param addr2 The other APR socket address.
  631.  * @remark The return value will be non-zero if the addresses
  632.  * are equivalent.
  633.  */
  634. APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
  635.                                     const apr_sockaddr_t *addr2);
  636.  
  637. /**
  638.  * Setup the memory required for poll to operate properly
  639.  * @param new_poll The poll structure to be used. 
  640.  * @param num The number of socket descriptors to be polled.
  641.  * @param cont The pool to operate on.
  642.  */
  643. APR_DECLARE(apr_status_t) apr_poll_setup(apr_pollfd_t **new_poll, 
  644.                                          apr_int32_t num,
  645.                                          apr_pool_t *cont);
  646.  
  647. /**
  648.  * Poll the sockets in the poll structure
  649.  * @param aprset The poll structure we will be using. 
  650.  * @param nsds The number of sockets we are polling. 
  651.  * @param timeout The amount of time in microseconds to wait.  This is 
  652.  *                a maximum, not a minimum.  If a socket is signalled, we 
  653.  *                will wake up before this time.  A negative number means 
  654.  *                wait until a socket is signalled.
  655.  * @remark
  656.  * <PRE>
  657.  * The number of sockets signalled is returned in the second argument. 
  658.  *
  659.  *        This is a blocking call, and it will not return until either a 
  660.  *        socket has been signalled, or the timeout has expired. 
  661.  * </PRE>
  662.  */
  663. APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t *nsds, 
  664.                                    apr_interval_time_t timeout);
  665.  
  666. /**
  667.  * Add a socket to the poll structure.
  668.  * @param aprset The poll structure we will be using. 
  669.  * @param socket The socket to add to the current poll structure. 
  670.  * @param event The events to look for when we do the poll.  One of:
  671.  * <PRE>
  672.  *            APR_POLLIN       signal if read will not block
  673.  *            APR_POLLPRI      signal if prioirty data is availble to be read
  674.  *            APR_POLLOUT      signal if write will not block
  675.  * </PRE>
  676.  */
  677. APR_DECLARE(apr_status_t) apr_poll_socket_add(apr_pollfd_t *aprset, 
  678.                                               apr_socket_t *sock,
  679.                                               apr_int16_t event);
  680.  
  681. /**
  682.  * Modify a socket in the poll structure with mask.
  683.  * @param aprset The poll structure we will be using. 
  684.  * @param sock The socket to modify in poll structure. 
  685.  * @param events The events to stop looking for during the poll.  One of:
  686.  * <PRE>
  687.  *            APR_POLLIN       signal if read will not block
  688.  *            APR_POLLPRI      signal if priority data is available to be read
  689.  *            APR_POLLOUT      signal if write will not block
  690.  * </PRE>
  691.  */
  692. APR_DECLARE(apr_status_t) apr_poll_socket_mask(apr_pollfd_t *aprset,
  693.                                                apr_socket_t *sock,
  694.                                                apr_int16_t events);
  695. /**
  696.  * Remove a socket from the poll structure.
  697.  * @param aprset The poll structure we will be using. 
  698.  * @param sock The socket to remove from the current poll structure. 
  699.  */
  700. APR_DECLARE(apr_status_t) apr_poll_socket_remove(apr_pollfd_t *aprset, 
  701.                                                  apr_socket_t *sock);
  702.  
  703. /**
  704.  * Remove all sockets from the poll structure.
  705.  * @param aprset The poll structure we will be using. 
  706.  * @param events The events to clear from all sockets.  One of:
  707.  * <PRE>
  708.  *            APR_POLLIN       signal if read will not block
  709.  *            APR_POLLPRI      signal if priority data is available to be read
  710.  *            APR_POLLOUT      signal if write will not block
  711.  * </PRE>
  712.  */
  713. APR_DECLARE(apr_status_t) apr_poll_socket_clear(apr_pollfd_t *aprset, 
  714.                                                  apr_int16_t events);
  715.  
  716. /**
  717.  * Get the return events for the specified socket.
  718.  * @param event The returned events for the socket.  One of:
  719.  * <PRE>
  720.  *            APR_POLLIN       Data is available to be read 
  721.  *            APR_POLLPRI      Priority data is availble to be read
  722.  *            APR_POLLOUT      Write will succeed
  723.  *            APR_POLLERR      An error occurred on the socket
  724.  *            APR_POLLHUP      The connection has been terminated
  725.  *            APR_POLLNVAL     This is an invalid socket to poll on.
  726.  *                             Socket not open.
  727.  * </PRE>
  728.  * @param sock The socket we wish to get information about. 
  729.  * @param aprset The poll structure we will be using. 
  730.  */
  731. APR_DECLARE(apr_status_t) apr_poll_revents_get(apr_int16_t *event, 
  732.                                           apr_socket_t *sock,
  733.                                           apr_pollfd_t *aprset);
  734.  
  735. /**
  736.  * Return the data associated with the current poll.
  737.  * @param pollfd The currently open pollfd.
  738.  * @param key The key to use for retrieving data associated with a poll struct.
  739.  * @param data The user data associated with the pollfd.
  740.  */
  741. APR_DECLARE(apr_status_t) apr_poll_data_get(apr_pollfd_t *pollfd, 
  742.                                            const char *key, void *data);
  743.  
  744. /**
  745.  * Set the data associated with the current poll.
  746.  * @param pollfd The currently open pollfd.
  747.  * @param data The key to associate with the data.
  748.  * @param key The user data to associate with the pollfd.
  749.  * @param cleanup The cleanup function
  750.  */
  751. APR_DECLARE(apr_status_t) apr_poll_data_set(apr_pollfd_t *pollfd, void *data,
  752.                                            const char *key,
  753.                                            apr_status_t (*cleanup)(void *));
  754.  
  755. #if APR_FILES_AS_SOCKETS || defined(DOXYGEN)
  756.  
  757. /**
  758.  * Convert a File type to a socket so that it can be used in a poll operation.
  759.  * @param newsock the newly created socket which represents a file.
  760.  * @param file the file to mask as a socket.
  761.  * @warning This is not available on all platforms.  Platforms that have the
  762.  *      ability to poll files for data to be read/written/exceptions will
  763.  *      have the APR_FILES_AS_SOCKETS macro defined as true.
  764.  */
  765. APR_DECLARE(apr_status_t) apr_socket_from_file(apr_socket_t **newsock,
  766.                                                apr_file_t *file);
  767.  
  768. #endif /* APR_FILES_AS_SOCKETS */
  769.  
  770. /**
  771.  * Given an apr_sockaddr_t and a service name, set the port for the service
  772.  * @param sockaddr The apr_sockaddr_t that will have its port set
  773.  * @param servname The name of the service you wish to use
  774.  */
  775. APR_DECLARE(apr_status_t) apr_getservbyname(apr_sockaddr_t *sockaddr, 
  776.                                             const char *servname);
  777.  
  778. /**
  779.  * Build an ip-subnet representation from an IP address and optional netmask or
  780.  * number-of-bits.
  781.  * @param ipsub The new ip-subnet representation
  782.  * @param ipstr The input IP address string
  783.  * @param mask_or_numbits The input netmask or number-of-bits string, or NULL
  784.  * @param p The pool to allocate from
  785.  */
  786. APR_DECLARE(apr_status_t) apr_ipsubnet_create(apr_ipsubnet_t **ipsub, const char *ipstr, 
  787.                                               const char *mask_or_numbits, apr_pool_t *p);
  788.  
  789. /**
  790.  * Test the IP address in an apr_sockaddr_t against a pre-built ip-subnet
  791.  * representation.
  792.  * @param ipsub The ip-subnet representation
  793.  * @param sa The socket address to test
  794.  * @return non-zero if the socket address is within the subnet, 0 otherwise
  795.  */
  796. APR_DECLARE(int) apr_ipsubnet_test(apr_ipsubnet_t *ipsub, apr_sockaddr_t *sa);
  797.  
  798. #if APR_HAS_SO_ACCEPTFILTER || defined(DOXYGEN)
  799. /**
  800.  * Set an OS level accept filter.
  801.  * @param sock The socket to put the accept filter on.
  802.  * @param name The accept filter
  803.  * @param args Any extra args to the accept filter.  Passing NULL here removes
  804.  *             the accept filter. 
  805.  */
  806. apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name,
  807.                                       char *args);
  808. #endif
  809.  
  810. /**
  811.  * Set a socket to be inherited by child processes.
  812.  * @param socket The socket to enable inheritance.
  813.  */
  814. APR_DECLARE(void) apr_socket_inherit_set(apr_socket_t *skt);
  815.  
  816. /** @deprecated @see apr_socket_inherit_set */
  817. APR_DECLARE(void) apr_socket_set_inherit(apr_socket_t *skt);
  818.  
  819. /**
  820.  * Unset a socket from being inherited by child processes.
  821.  * @param socket The socket to disable inheritance.
  822.  */
  823. APR_DECLARE(void) apr_socket_inherit_unset(apr_socket_t *skt);
  824.  
  825. /** @deprecated @see apr_socket_inherit_unset */
  826. APR_DECLARE(void) apr_socket_unset_inherit(apr_socket_t *skt);
  827.  
  828. #ifdef __cplusplus
  829. }
  830. #endif
  831. /** @} */
  832. #endif  /* ! APR_NETWORK_IO_H */
  833.  
  834.